package member.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import member.domain.Member;
import member.service.MemberService;

public class SerchMemberServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String url = null;
//		1. 요청파라미터 조회 - 검증
		String id = request.getParameter("id");
//		요청파라미터 검증 : 만약 id가 null이거나 ""일 경우 -> search_member.jsp로 이동
		if(id==null||id.trim().length()==0){
			url = "/member/search_member.jsp";
			request.setAttribute("message", "Please cheak your");
		}else{
	//		2. Business 로직 처리
	//		MemberService 조회처리 메소드 호출
			MemberService service = MemberService.getInstance();
			Member mem = service.serchMemberById(id);
	//		3. 처리 결과 응답 - member_info.jsp 호출
	//		request scope의 attribute로 조회한 member객체를 binding(저장)
			request.setAttribute("member", mem);
			url="/member/member_info.jsp";
		}
		RequestDispatcher rdp = request.getRequestDispatcher(url);
//		리퀘스트디스페처 객체 rdp를 만들어서 그 안에 
		rdp.forward(request, response);
	}

}
